﻿// JScript File


function ExtendedTextInteraction(owner)
{
    this.owner = owner;
    var xmldom = CreateXmlDOM();
    this.Interact = function(event)
    {            
        var aEvent = event ? event : window.event;        
        var txt = aEvent.srcElement ? aEvent.srcElement : aEvent.target;
        var userResponse = this.owner.xml.getElementsByTagName("userResponse")[0];
        var vNodes = userResponse.getElementsByTagName("value");
        
        var vNode = null;
        if (vNodes.length > 0)
            vNode = vNodes[0];
            
        if (vNode == null)
        {                            
            vNode = xmldom.createElement("value");
            var urNode = this.owner.xml.getElementsByTagName("userResponse")[0];
            urNode.appendChild(vNode); //а вы хоть представляете, как сложно писать без IntelliSense?
        }                
        
        
        if (!isMozilla)
            vNode.text = TransformFromTextAreaToHTML(txt.value);
        else
            vNode.textContent = TransformFromTextAreaToHTML(txt.value);           
        
    }        
}

function TransformFromTextAreaToHTML(text)
{
    return text;
    
    var html = '';
    for (var i = 0; i < text.length; i++)
    {
        if (text.charCodeAt(i) == 10)
            html += '<br />';
        else if (text.charCodeAt(i) != 13)
            html += text[i];            
    }
    
    return html;
}
   
function ExtendedTextRendering(owner)
{
    this.owner = owner;
    
    this.Render = function()
    {
        try
        {
            var html = "";
            html += TransformNode(this.owner.xml, "xslt/ItemHeader.xsl.aspx");
            var itemBody = this.owner.xml.getElementsByTagName("itemBody")[0];            
            var p = itemBody.getElementsByTagName("p");            
            if (p.length > 0)
                html += SerializeXmlNode(p[0]);                          
            html += TransformNode(this.owner.xml, "xslt/ExtendedTextInteraction.xsl");
            return html;
        }
        catch (e)
        {
            ShowMessage("Error:" + (e.message == undefined ? e : e.message));
        }
    }
}
